package com.lei.leetcode;


import java.util.LinkedList;

/**
 * @Author LeiXiaoLei
 * @Date 2022/7/21 20:03
 * @Version 1.0
 */
public class S_225 {
    private LinkedList<Integer> a;//输入队列
    private LinkedList<Integer> b;//输出队列

    public S_225() {
        a = new LinkedList<>();
        b = new LinkedList<>();
    }

    public void push(int x) {
        a.addLast(x);
        // 将b队列中元素全部转给a队列
        while (!b.isEmpty())
            a.add(b.removeFirst());
        // 交换a和b,使得a队列没有在push()的时候始终为空队列
        LinkedList<Integer> temp = a;
        a = b;
        b = temp;
    }

    public int pop() {
        return b.removeFirst();
    }

    public int top() {
        return b.getFirst();
    }

    public boolean empty() {
        return b.isEmpty();
    }

    @Override
    public String toString() {
        return "S_225{" +
                "a=" + a +
                ", b=" + b +
                '}';
    }

    public static void main(String[] args) {
        S_225 s = new S_225();
        //["MyStack","push","push","top","pop","empty"]
        //[[],[1],[2],[],[],[]]
        s.push(1);
        s.push(2);

        System.out.println(s);
        System.out.println(s.top());
        System.out.println(s.top());
        System.out.println(s.empty());
        System.out.println(s);
    }
}

/**
 * Your MyStack object will be instantiated and called as such:
 * MyStack obj = new MyStack();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.top();
 * boolean param_4 = obj.empty();
 */